import { BehaviorSubject, debounceTime, of, switchMap } from "rxjs";
import { sleepSync } from "./utils.ts";

const source = new BehaviorSubject(0);

const bs = source.pipe(
  debounceTime(1000),
  switchMap((n) => of(n * 2)),
);

const sub = bs.subscribe(console.log);
setTimeout(() => console.log(sub.closed), 3000);

for (let i = 2; i <= 5; i++) {
  sleepSync(200);
  source.next(i);
}
